<?php

	class EbResponse
	{
		const HTML = "html";
		const XML = "xml";
		const JSON = "json";
	
		var $url;
		var $listHeaders;
		var $content;
		var $type;
		
		function __construct()
		{
			$this->type = "html";
			$this->listHeaders = array();
		}
		
		public function render()
		{
			header('Content-Type: text/html; charset=UTF-8');
		
			foreach ($this->listHeaders AS $key=>$value)
			{
				header("$key:$value");
			}
			
			if ($this->type === EbResponse::HTML)
			{			
				if (is_string($this->content))
				{
					die($this->content);
				}
				else
				{
					die(eb_var_dump($this->content));
				}
			}
			elseif ($this->type === EbResponse::JSON)
			{				
				die (json_encode($this->content));
			}
			elseif ($this->type === EbResponse::XML)
			{
//				include (EBUILDY_PATH."lib/Serializer.php");
//				$serializer = new XML_Serializer();
//				$serializer->setOption("addDecl", true);
//				$serializer->setOption("rootName", "model"); 
//				$serializer->setOption("scalarAsAttributes", true);
//				$serializer->serialize($this->content);
				echo '<?xml version="1.0" encoding="UTF-8" ?>';
				
				if (is_array($this->content))
				{
					die (EbXMLToolkit::objectToXML($this->content));
				}
				else
				{
					die($this->content);
				}
			}
			else
			{				
				throw new Exception ("Error: the response type '".$this->type."' is not defined!");
			}
		}
	}
	
?>